package org.sabayframework.mem.impl;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ReadOnlyBufferException;

import org.sabayframework.mem.BigBuffer;

/**
 * Read-only wrapper around a BigBuffer instance.
 * */
public final class ReadOnlyBigBuffer implements BigBuffer {
	private final BigBuffer buffer;
	
	public ReadOnlyBigBuffer(BigBuffer buffer) {
		super();
		if(buffer instanceof ReadOnlyBigBuffer) 
			this.buffer = ((ReadOnlyBigBuffer)buffer).getBuffer();
		else 
			this.buffer = buffer;
	}
	/**
	 * Returns wrapped buffer.
	 * Not an interface method. 
	 * */
	public BigBuffer getBuffer() {
		return buffer;
	}

	public long capacity() {
		return buffer.capacity();
	}

	public long position() {
		return buffer.position();
	}

	public BigBuffer position(long newPosition) {
		return buffer.position(newPosition);
	}

	public long limit() {
		return buffer.limit();
	}

	public BigBuffer limit(long newLimit) {
		return buffer.limit(newLimit);
	}

	public BigBuffer flip() {
		return buffer.flip();
	}

	public BigBuffer rewind() {
		return buffer.rewind();
	}

	public long remaining() {
		return buffer.remaining();
	}

	public boolean hasRemaining() {
		return buffer.hasRemaining();
	}

	public boolean isDirect() {
		return buffer.isDirect();
	}

	public ByteOrder order() {
		return buffer.order();
	}

	public byte get() {
		return buffer.get();
	}

	public short getShort() {
		return buffer.getShort();
	}

	public int getInt() {
		return buffer.getInt();
	}

	public long getLong() {
		return buffer.getLong();
	}

	public float getFloat() {
		return buffer.getFloat();
	}

	public double getDouble() {
		return buffer.getDouble();
	}

	public char getChar() {
		return buffer.getChar();
	}

	public void get(byte[] dst) {
		buffer.get(dst);
	}

	public void get(byte[] dst, int offset, int length) {
		buffer.get(dst, offset, length);
	}

	public void get(short[] dst) {
		buffer.get(dst);
	}

	public void get(short[] dst, int offset, int length) {
		buffer.get(dst, offset, length);
	}

	public void get(char[] dst) {
		buffer.get(dst);
	}

	public void get(char[] dst, int offset, int length) {
		buffer.get(dst, offset, length);
	}

	public void get(int[] dst) {
		buffer.get(dst);
	}

	public void get(int[] dst, int offset, int length) {
		buffer.get(dst, offset, length);
	}

	public void get(float[] dst) {
		buffer.get(dst);
	}

	public void get(float[] dst, int offset, int length) {
		buffer.get(dst, offset, length);
	}

	public void get(long[] dst) {
		buffer.get(dst);
	}

	public void get(long[] dst, int offset, int length) {
		buffer.get(dst, offset, length);
	}

	public void get(double[] dst) {
		buffer.get(dst);
	}

	public void get(double[] dst, int offset, int length) {
		buffer.get(dst, offset, length);
	}

	@Override
	public BigBuffer clear() {
		return buffer.clear();
	}

	public byte get(long index) {
		return buffer.get(index);
	}

	public char getChar(long index) {
		return buffer.getChar(index);
	}

	public short getShort(long index) {
		return buffer.getShort(index);
	}

	public int getInt(long index) {
		return buffer.getInt(index);
	}

	public float getFloat(long index) {
		return buffer.getFloat(index);
	}

	public long getLong(long index) {
		return buffer.getLong(index);
	}

	public double getDouble(long index) {
		return buffer.getDouble(index);
	}

	@Override
	public boolean isReadOnly() {
		return true;
	}

	@Override
	public boolean hasArray() {
		return false;
	}

	@Override
	public byte[] array() {
		throw new ReadOnlyBufferException();
	}

	@Override
	public int arrayOffset() {
		throw new ReadOnlyBufferException();
	}

	@Override
	public BigBuffer slice() {
		return new ReadOnlyBigBuffer(buffer.slice());
	}

	@Override
	public BigBuffer duplicate() {
		return new ReadOnlyBigBuffer(buffer.duplicate());
	}

	@Override
	public BigBuffer asReadOnlyBuffer() {
		return this;
	}

	public BigBuffer compact() {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(long index, byte value) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void putChar(long index, char value) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void putShort(long index, short value) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void putInt(long index, int value) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void putFloat(long index, float value) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void putLong(long index, long value) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void putDouble(long index, double value) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(byte b) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void putShort(short value) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void putInt(int value) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void putLong(long value) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void putFloat(float value) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void putDouble(double value) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void putChar(char value) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(byte[] src) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(byte[] src, int offset, int length) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(short[] src) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(short[] src, int offset, int length) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(char[] src) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(char[] src, int offset, int length) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(int[] src) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(int[] src, int offset, int length) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(float[] src) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(float[] src, int offset, int length) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(long[] src) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(long[] src, int offset, int length) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(double[] src) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(double[] src, int offset, int length) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(BigBuffer src) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public void put(ByteBuffer src) {
		throw new ReadOnlyBufferException();
	}

	@Override
	public int hashCode() {
		return buffer.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		return !buffer.equals(obj);
	}

	@Override
	public int compareTo(BigBuffer buffer) {
		return buffer.compareTo(buffer);
	}

	@Override
	public String toString() {
		return "ReadOnlyBigBuffer [buffer=" + buffer + "]";
	}

	public void destroy() {
		buffer.destroy();
	}
		
}
